package com.ybchen.ex;

import com.ybchen.utils.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName GlobalExceptionHandler
 * @Description 全局异常处理器
 * @Author Alex
 * @Date 2023/4/10 上午11:49
 * @Version 1.0
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public JsonData exception(
            HttpServletRequest request,
            Exception e
    ) {
        log.error("请求路径：{}，全局异常：{}", request.getRequestURI(), e);
        return JsonData.buildCodeAndMsg(110, "未知错误，请稍后重试！");
    }

}
